package com.viewflipper;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.ViewFlipper;

public class Activity1 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set main.XML as the layout for this Activity
        setContentView(R.layout.main);
        //setContentView(R.layout.main_single_view_flipper);

        // Add a few countries to the spinner
        Spinner spinnerCountries = (Spinner) findViewById(R.id.spinner_country);
        ArrayAdapter<String> countryArrayAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_dropdown_item,
                    new String[] { "Canada", "USA" });
        spinnerCountries.setAdapter(countryArrayAdapter);
        
     
        // Set the listener for Button_Next, a quick and dirty way to create a listener
        Button buttonNext = (Button) findViewById(R.id.Button_next);
        buttonNext.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                // Get the ViewFlipper from the layout
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);

                // Set an animation from res/anim: I pick push left in
                
                
                Animation a1 = AnimationUtils.loadAnimation(view.getContext(), R.anim.push_left_out);
                //a1.setDuration(1000);
                Animation a2 = AnimationUtils.loadAnimation(view.getContext(), R.anim.slide_left);
                //a2.setDuration(1000);       
                vf.setOutAnimation(a1);
                vf.setInAnimation(a2);
                
                //vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(), R.anim.shake));
                vf.showNext();

        }
        });

        // Set the listener for Button_Previous, a quick and dirty way to create a listener
        Button buttonPrevious = (Button) findViewById(R.id.Button_previous);
        buttonPrevious.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                // Get the ViewFlipper from the layout
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                // Set an animation from res/anim: I pick push left out
                //vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(), R.anim.wave_scale));
                
                Animation a1 = AnimationUtils.loadAnimation(view.getContext(), R.anim.slide_right_out);
                //a1.setDuration(1000);
                Animation a2 = AnimationUtils.loadAnimation(view.getContext(), R.anim.slide_in_left);
                //a2.setDuration(1000);       
                vf.setOutAnimation(a1);
                vf.setInAnimation(a2);
                //vf.setInAnimation(null);
                
                vf.showPrevious();
        }

        });        

    }
}